package dataAccess;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionDB {
	
    private Connection connectionDB = null;
	
	public ConnectionDB() {
     try {
/*		Class.forName("com.mysql.jdbc.Driver");
   		String url = "jdbc:mysql://"+host+":3306/Usuarios";
    		String user = "root";
    		String password = "mysql";
*/	 
        
      String host = "localhost"; 
      Class.forName("org.postgresql.Driver");
 	   String url = "jdbc:postgresql://"+host+":5432/T2Scocina", 
 	          user="postgres",
 	          password="A01230690";  ///////////////////////////////PASSWORD
		connectionDB = DriverManager.getConnection(url, user, password);
     } catch (SQLException sqle){
    	 sqle.printStackTrace();
     } catch (Exception e){
    	 e.printStackTrace();
     }
   }
	
	public ConnectionDB(String driver, String url, String user, String password) {
	     try {
			Class.forName(driver);
			connectionDB = DriverManager.getConnection(url, user, password);
	     } catch (SQLException sqle){
	    	 sqle.printStackTrace();
	     } catch (Exception e){
	    	 e.printStackTrace();
	     }
	   }
	
   public Connection getConnectionDB() {
	   return connectionDB;
   }
   
   public void setConnectionDB(Connection connectionDB) {
	   this.connectionDB = connectionDB;
   }
   
   public void closeConnectionDB(){
      if (connectionDB!=null) {
    	  try {
             connectionDB.close();
          }
          // process SQLException on close operation
         catch ( SQLException sqlException ) {
              sqlException.printStackTrace();
          }
      }
  }
}
